#####
#####
###     Creating scatterplots of other state policy measures
###     versus the mean ideal points
#####
#####

library(lattice)

###
###   Read data from "All measures, with names.txt"
###

states <- read.table(file.choose(), header = T)

###
###   Transform ideal point values to match proportions 
###   of spending, and shift mean value to zero
###

states$idlpt2 <- -1.62519  + (states$idlpt * 4.50)

summary(states$idlpt2)

states$idlpt2 <- states$idlpt2 - 0.6673232

summary(states$idlpt2)

###
###   Scatterplots showing mean (transformed) ideal 
###   point values for states plotted against other
###   state policy measures
###


###   Walker

fig5a <-
xyplot(walker ~ idlpt2, data = states,
   aspect = 1,
   panel = function (x, y) {
   panel.xyplot(x, y, col = "black", cex = .75)
   panel.loess(x, y, span = .75, degree = 1, family = "symmetric",
      col = "black")
   },
   xlab = list("Mean state spending priority score", cex = .65),
   ylab = list("Policy innovation score", cex = .65),
   main = list("A. State policy innovation index", 
    cex = .65),
   scales = list(cex = .65)
)


###  Hofferbert and Sharkansky

fig5b <-
xyplot(hoff1 ~ idlpt2, data = states,
   aspect = 1,
   panel = function (x, y) {
   panel.xyplot(x, y, col = "black", cex = .75)
   panel.loess(x, y, span = .75, degree = 1, family = "symmetric",
      col = "black")
   },
   xlab = list("Mean state spending priority score", cex = .65),
   ylab = list("Welfare-education factor", cex = .65),
   main = list("B. Welfare-education factor", 
     cex = .65),
   scales = list(cex = .65)
)


### Klingman and Lammers

fig5c <-
xyplot(kling ~ idlpt2, data = states,
   aspect = 1,
   panel = function (x, y) {
   panel.xyplot(x, y, col = "black", cex = .75)
   panel.loess(x, y, span = .75, degree = 1, family = "symmetric",
      col = "black")
   },
   xlab = list("Mean state spending priority score", cex = .65),
   ylab = list("General policy liberalism factor", cex = .65),
   main = list("C. General policy liberalism factor",
     cex = .65),
   scales = list(cex = .65)
)


###   Wright, Erikson, McIver

fig5d <-
xyplot(Ewm ~ idlpt2, data = states,
   aspect = 1,
   panel = function (x, y) {
   panel.xyplot(x, y, col = "black", cex = .75)
   panel.loess(x, y, span = .75, degree = 1, family = "symmetric",
      col = "black")
   },
   xlab = list("Mean state spending priority score", cex = .65),
   ylab = list("Index of composite policy liberalism", cex = .65),
   main = list("D. Composite policy liberalism index",
     cex = .65),
   scales = list(cex = .65)
)

###
###   The following print functions place the four
###   scatterplots on the same page, producing 
###   Figure 5 from the PA article
###

print(fig5a, position = c(0, .52, .48, 1), more = T)

print(fig5b, position = c(.52, .52, 1, 1), more = T)

print(fig5c, position = c(0, 0, .48, .48), more = T)

print(fig5d, position = c(.52, 0, 1, .48), more = F)


